home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / POSTSCPT / GSVIEW / SRC / GVWMISC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  4.5 KB  |  187 lines

  1. /* Copyright (C) 1993, 1994, Russell Lang.  All rights reserved.
  2.   
  3.   This file is part of GSview.
  4.   
  5.   This program is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the GSview Free Public Licence 
  9.   (the "Licence") for full details.
  10.   
  11.   Every copy of GSview must include a copy of the Licence, normally in a 
  12.   plain ASCII text file named LICENCE.  The Licence grants you the right 
  13.   to copy, modify and redistribute GSview, but only under certain conditions 
  14.   described in the Licence.  Among other things, the Licence requires that 
  15.   the copyright notice and this notice be preserved on all copies.
  16. */
  17.  
  18. /* gvwmisc.c */
  19. /* Miscellaneous Windows GSview routines */
  20.  
  21. #include "gvwin.h"
  22.  
  23. /* SetDlgItemText is a Windows API */
  24.  
  25. void
  26. post_close(void)
  27. {
  28.     PostMessage(hwndimg, WM_CLOSE, (WPARAM)0, (LPARAM)0);
  29. }
  30.  
  31. void
  32. get_help(void)
  33. {
  34.     SendMessage(hwndimg, help_message, 0, 0L);
  35. }
  36.  
  37. /* display message */
  38. int message_box(char *str, int icon)
  39. {
  40.     return MessageBox(hwndimg, str, szAppName, icon | MB_OK);
  41. }
  42.  
  43. /* change menu item checkmark */
  44. void
  45. check_menu_item(int menuid, int itemid, BOOL checked)
  46. {
  47.     menuid = menuid;    /* shut up warning */
  48.         CheckMenuItem(hmenu, itemid, MF_BYCOMMAND | (checked ? MF_CHECKED : MF_UNCHECKED));
  49. }
  50.  
  51. /* get text of menu item */
  52. int
  53. get_menu_string(int menuid, int itemid, char *str, int len)
  54. {
  55.     menuid = menuid;    /* shut up warning */
  56.     return GetMenuString(hmenu, itemid, str, len, MF_BYCOMMAND);
  57. }
  58.  
  59. int
  60. load_string(int id, char *str, int len)
  61. {
  62.     return LoadString(phInstance, id, str, len);
  63. }
  64.  
  65. void
  66. play_sound(int num)
  67. {
  68.     if (strlen(sound[num].file)==0)
  69.         return;
  70.     if (!is_win31 || (strcmp(sound[num].file,BEEP)==0)) {
  71.         MessageBeep(-1);
  72.         return;
  73.     }
  74.     if (is_win31) {
  75.         if (lpfnSndPlaySound != (FPSPS)NULL) 
  76.                lpfnSndPlaySound(sound[num].file, SND_SYNC);
  77.         else
  78.             MessageBeep(-1);
  79.         return;
  80.     }
  81. }
  82.  
  83.  
  84. /* display or remove 'wait' message */
  85. void
  86. info_wait(int id)
  87. {
  88. HWND hwnd;
  89. POINT pt;
  90.     if (id)
  91.         load_string(id, szWait, sizeof(szWait));  /* revert to generic text */
  92.     else
  93.         szWait[0] = '\0';
  94.  
  95.     InvalidateRect(hwndimg, (LPRECT)&info_rect, FALSE);
  96.     UpdateWindow(hwndimg);
  97.  
  98.     if (szWait[0] != '\0') {
  99.             GetCursorPos(&pt);
  100.         hwnd = WindowFromPoint(pt);
  101.         if ((hwnd == hwndimg) || IsChild(hwndimg,hwnd))
  102.         SetCursor(hcWait);
  103.     }
  104.     else {
  105.         /* set cursor to that of active window */
  106.         hwnd = GetFocus();
  107.         if ( (hwndimgchild && IsWindow(hwndimgchild))
  108.           && ((hwnd == hwndimg) || (hwnd == hwndimgchild)) ) {
  109.         if (in_child_client_area()) {
  110.             SetCursor(GetClassCursor(hwndimgchild));
  111.             return;
  112.         }
  113.         }
  114.         SetCursor(GetClassCursor(hwnd));
  115.     }
  116. }
  117.  
  118. /* change directory and drive */
  119. int
  120. gs_chdir(char *dirname)
  121. {
  122. #ifdef __WIN32__
  123.     SetCurrentDirectory(dirname);
  124. #else
  125.     if (isalpha(dirname[0]) && (dirname[1]==':'))
  126.         (void) setdisk(toupper(dirname[0])-'A');
  127.     if (!((strlen(dirname)==2) && isalpha(dirname[0]) && (dirname[1]==':')))
  128.         chdir(dirname);
  129. #endif
  130.     return 0;
  131. }
  132.  
  133. char * 
  134. gs_getcwd(char *dirname, int size)
  135. {
  136. #ifdef __WIN32__
  137.     GetCurrentDirectory(size, dirname);
  138.     return dirname;
  139. #else
  140.     return getcwd(dirname, size);
  141. #endif
  142. }
  143.  
  144.  
  145. void
  146. send_prolog(FILE *f, int resource)
  147. {  
  148. HGLOBAL hglobal;
  149. LPSTR prolog;
  150.     hglobal = LoadResource(phInstance, 
  151.         FindResource(phInstance, MAKEINTRESOURCE(resource), RT_RCDATA));
  152.     if ( (prolog = (LPSTR)LockResource(hglobal)) != (LPSTR)NULL) {
  153.         while (*prolog) {
  154.         if (debug_file != (FILE *)NULL)
  155.                 fputc(*prolog, debug_file);
  156.             fputc(*prolog++, f);
  157.         }
  158.         FreeResource(hglobal);
  159.     }
  160. }
  161.  
  162. void
  163. profile_create_section(PROFILE *prf, char *section, int id)
  164. {  
  165. HGLOBAL hglobal;
  166. LPSTR entry, value;
  167. char name[MAXSTR];
  168. char val[256];
  169.     hglobal = LoadResource(phInstance, 
  170.         FindResource(phInstance, MAKEINTRESOURCE(id), RT_RCDATA));
  171.     if ( (entry = (LPSTR)LockResource(hglobal)) == (LPSTR)NULL)
  172.         return;
  173.     while (lstrlen(entry)!=0) {
  174.         for ( value = entry; 
  175.           (*value!='\0') && (*value!=',') && (*value!='='); 
  176.           value++)
  177.         /* nothing */;
  178.         _fstrncpy(name, entry, (int)(value-entry));
  179.         name[(int)(value-entry)] = '\0';
  180.         value++;
  181.         _fstrncpy(val, value, sizeof(val));
  182.         profile_write_string(prf, section, name, val);
  183.         entry = value + lstrlen(value) + 1;
  184.     }
  185.     FreeResource(hglobal);
  186. }
  187.